import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects

Item {

    // 添加属性来存储gamma的三个参数
    property real gammaX: 1.0
    property real gammaY: 0.4
    property real gammaZ: 2.0

    Flow {

        anchors.fill: parent
        spacing: 10
        padding: 10

        Rectangle {
            width: 280
            height: 280
            color: "white"

            Image {
                id: butterfly
                source: "qrc:/images/butterfly.png"
                sourceSize: Qt.size(parent.width, parent.height)
                smooth: true
                visible: false
            }

            LevelAdjust {
                anchors.fill: butterfly
                source: butterfly
                gamma: Qt.vector3d(gammaX, gammaY, gammaZ)
                minimumInput: "#000000"
                maximumInput: "#ffffff"
                minimumOutput: "#000000"
                maximumOutput: "#ffffff"
            }
        }

        // 添加控制面板
        Rectangle {
            width: 250
            height: 200
            border.color: "#cccccc"
            radius: 5

            Column {
                anchors.fill: parent
                anchors.margins: 10
                spacing: 10

                Text {
                    text: "Gamma 控制"
                    font.pixelSize: 16
                    font.bold: true
                }

                // Gamma X 滑块
                Row {
                    spacing: 10
                    Text {
                        text: "Gamma X:"
                        width: 60
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    Slider {
                        id: gammaXSlider
                        width: 120
                        from: 0.1
                        to: 3.0
                        value: gammaX
                        onValueChanged: gammaX = value
                    }
                    Text {
                        text: gammaX.toFixed(2)
                        width: 40
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }

                // Gamma Y 滑块
                Row {
                    spacing: 10
                    Text {
                        text: "Gamma Y:"
                        width: 60
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    Slider {
                        id: gammaYSlider
                        width: 120
                        from: 0.1
                        to: 3.0
                        value: gammaY
                        onValueChanged: gammaY = value
                    }
                    Text {
                        text: gammaY.toFixed(2)
                        width: 40
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }

                // Gamma Z 滑块
                Row {
                    spacing: 10
                    Text {
                        text: "Gamma Z:"
                        width: 60
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    Slider {
                        id: gammaZSlider
                        width: 120
                        from: 0.1
                        to: 3.0
                        value: gammaZ
                        onValueChanged: gammaZ = value
                    }
                    Text {
                        text: gammaZ.toFixed(2)
                        width: 40
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }

                // 重置按钮
                Button {
                    text: "重置为默认值"
                    onClicked: {
                        gammaX = 1.0
                        gammaY = 0.4
                        gammaZ = 2.0
                    }
                }
            }
        }
    }
}
